package com.xjlsoft.weather.enums;


import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import com.xjlsoft.weather.service.WeatherTaskJob;
import com.xjlsoft.weather.task.*;

/**
 * 定时任务枚举值
 * 注：key 需要与数据库任务表 taks_key 保持一致
 * 此数据也可以维护到表里
 *
 * @author 码农猿
 */
public enum WeatherTaskEnum {

    /**
     * 任务1
     */
	GroundDataTask("GroundDataTask", new GroundDataTask()),
    /**
     * 任务2
     */
	AerosolDataTask("AerosolDataTask", new AerosolDataTask()),
    /**
     * 任务3
     */
	HighDataTask("HighDataTask", new HighDataTask()),
    /**
     * 任务4
     */
	RadiationTask("RadiationTask", new RadiationTask()),
	
	GroundDataTaskTimin("GroundDataTaskTimin", new GroundDataTaskTimin()),
	
	AerosolDataTaskTimin("AerosolDataTaskTimin", new AerosolDataTaskTimin()),
	
	HighDataTaskTimin("HighDataTaskTimin", new HighDataTaskTimin()),
	
	RadiationTaskTimin("RadiationTaskTimin", new RadiationTaskTimin()),
	AvgDayTask("AvgDayTask", new AvgDayTask()),
	AvgWeekTask("AvgWeekTask", new AvgWeekTask()),
	AvgMonTask("AvgMonTask", new AvgMonTask()),
	AvgYearTask("AvgYearTask", new AvgYearTask()),
	
	GroundPreTask("GroundPreTask", new GroundPreTask()),
	GroundTemTask("GroundTemTask", new GroundTemTask()),
	GroundOtherTask("GroundOtherTask", new GroundOtherTask()),
	RadiationMinTask("RadiationMinTask", new RadiationMinTask()),
	GroundPreTaskTimin("GroundPreTaskTimin", new GroundPreTaskTimin()),
	GroundTemTaskTimin("GroundTemTaskTimin", new GroundTemTaskTimin()),
	GroundOtherTaskTimin("GroundOtherTaskTimin", new GroundOtherTaskTimin()),
	RadiationMinTaskTimin("RadiationMinTaskTimin", new RadiationMinTaskTimin());
	
	 public String getValue() {
	        return taskKey;
	    }
    /**
     * 定时任务key
     */
    private String taskKey;
    /**
     * 定时任务 执行实现类
     */
    private WeatherTaskJob weatherTaskJob;

    WeatherTaskEnum(String taskKey, WeatherTaskJob weatherTaskJob) {
        this.taskKey = taskKey;
        this.weatherTaskJob = weatherTaskJob;
    }

    /**
     * 初始化 所有任务
     */
    public static Map<String, WeatherTaskJob> initScheduledTask() {
        if (WeatherTaskEnum.values().length < 0) {
            return new ConcurrentHashMap<>();
        }
        
        Map<String, WeatherTaskJob> scheduledTaskJobMap = new ConcurrentHashMap<>();
        
        for (WeatherTaskEnum taskEnum : WeatherTaskEnum.values()) {
        	
            scheduledTaskJobMap.put(taskEnum.taskKey, taskEnum.weatherTaskJob);
        }

        return scheduledTaskJobMap;
    }
}